﻿@{
var user = ViewBag.User;
var isUser = (user != null);
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0" />
  <title>@ViewData["Title"] - 网上商城</title>
  <link rel="stylesheet"
        href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
  <link rel="stylesheet"
        href="~/lib/bootstrap/dist/font/bootstrap-icons.css" />
  <link rel="stylesheet"
        href="~/css/site.css"
        asp-append-version="true" />
  <link rel="stylesheet"
        href="~/ShopForWeb.UI.styles.css"
        asp-append-version="true" />
</head>

<body>
  <header>
    <nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
      <div class="container-fluid">
        <a class="navbar-brand"
           asp-area=""
           asp-controller="Home"
           asp-action="Index"><i class="bi bi-shop"></i>&nbsp;网上商城</a>
        <button class="navbar-toggler"
                type="button"
                data-bs-toggle="collapse"
                data-bs-target=".navbar-collapse"
                aria-controls="navbarSupportedContent"
                aria-expanded="false"
                aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>
        <div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
          <ul class="navbar-nav flex-grow-1">
            <li class="nav-item">
              <a class="nav-link text-dark"
                 asp-area=""
                 asp-controller="Home"
                 asp-action="Index"><i class="bi bi-bank"></i>&nbsp;首页</a>
            </li>
            <li class="nav-item">
              <a class="nav-link text-dark"
                 asp-area=""
                 asp-controller="Commodity"
                 asp-action="GetPage"><i class="bi bi-basket"></i>&nbsp;商品</a>
            </li>
            @if(isUser){
            <li class="nav-item">
              <a class="nav-link text-dark"
                 asp-area=""
                 asp-controller="Order"
                 asp-action="GetPage">我的订单</a>
            </li>
            <li class="nav-item">
              <a class="nav-link text-dark"
                 asp-area=""
                 asp-controller="ShopCart"
                 asp-action="index">购物车</a>
            </li>
            <li class="nav-item">
              <a class="nav-link text-dark"
                 asp-area=""
                 asp-controller="User"
                 asp-action="Logout">安全退出</a>
            </li>
            <li class="nav-item">
              <a class="nav-link text-dark"
                 asp-area=""
                 asp-controller="Commodity"
                 asp-action="GetPage">个人中心(@user?.Name)</a>
            </li>
            }
          </ul>

          @if(!isUser){
          <form class="row mt-3"
                id="denglu">
            <div class="col-auto">
              <label for="staticEmail2"
                     class="visually-hidden">Email</label>
              <div class="input-group mb-3">
                <span class="input-group-text"
                      id="basic-addon1"><i class="bi bi-phone"></i></span>
                <input type="text"
                       id="phone"
                       class="form-control form-control-sm"
                       placeholder="请输入手机号"
                       aria-label="phone"
                       aria-describedby="basic-addon1">
              </div>
            </div>
            <div class="col-auto">
              <label for="inputPassword2"
                     class="visually-hidden">Password</label>
              <div class="input-group mb-3">
                <span class="input-group-text"
                      id="basic-addon1"><i class="bi bi-eye-slash"></i></span>
                <input type="password"
                       id="password"
                       class="form-control form-control-sm"
                       placeholder="请输入密码"
                       aria-label="password"
                       aria-describedby="basic-addon1">
              </div>
            </div>
            <div class="col-auto">
              <button type="button"
                      id="btn-login"
                      class="btn btn-primary mb-3 btn-sm">登录</button>&nbsp;|&nbsp;
              <button type="button"
                      class="btn btn-link mb-3 btn-sm">注册</button>
            </div>
          </form>
          }

        </div>
      </div>
    </nav>
  </header>
  <div class="container">
    <main role="main"
          class="pb-3">
      @RenderBody()
    </main>
  </div>

  <footer class="border-top footer text-muted">
    <div class="container">
      &copy; 2022 - ShopForWeb.UI - <a asp-area=""
         asp-controller="Home"
         asp-action="Privacy">Privacy</a>
    </div>
  </footer>
  <script src="~/lib/jquery/dist/jquery.min.js"></script>
  <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
  <script src="~/js/site.js"
          asp-append-version="true"></script>

  <script>
    $(function () {
      $("#btn-login").on("click", function () {
        $.ajax({
          type: "post",
          url: "/identity/login",
          data: {
            phone: $("#phone").val(),
            password: $("#password").val()
          },
          success: function (response) {
            alert(response.message);
            if (response.status == 0)
              location.reload();
          }
        });
      })
    });
  </script>
  @await RenderSectionAsync("Scripts", required: false)

</body>

</html>
